<#
规则链接验证（原生 PowerShell）
用途：验证 docs/meta_index.md 是否索引关键规则文档。
用法：
  pwsh -File scripts/windows/verify_rule_linkages.ps1
#>
param()

$WindowsDir = Split-Path -Parent $PSCommandPath
$ScriptsDir = Split-Path -Parent $WindowsDir
$RepoDir = Split-Path -Parent $ScriptsDir

$meta = Join-Path $RepoDir 'docs/meta_index.md'
if (!(Test-Path $meta)) { Write-Error "缺少 meta_index：$meta"; exit 2 }
$raw = Get-Content -Raw $meta

$keys = @(
  'rules/project_rules.md',
  'rules/framework_info.md',
  'rules/ai_rules_and_prompts.md',
  'rules/git_commit_standards.md'
)
$miss = $keys | Where-Object { $raw -notmatch [regex]::Escape($_) }
if ($miss.Count -gt 0) {
  Write-Warning "缺失规则索引：`n - " + ($miss -join "`n - ")
  exit 2
} else { Write-Host "规则链接验证通过"; exit 0 }
